﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Cosmetic.Logic;
using System.Collections.Generic;
using Cosmetic.DataEntity;


public partial class CategoryList : System.Web.UI.UserControl
{
     private CategoryManager m_CategoryManager = new CategoryManager();

    private int m_ShowCount = 10;
    public int ShowCount
    {
        get { return m_ShowCount; }
        set { m_ShowCount = value; }
    }

    private string m_imageSrc = "~/imagesWeb/product_01.gif";
    public string imageSrc
    {
        get { return m_imageSrc; }
        set { m_imageSrc = value; }
    }

    private string m_Category ;
    public string Category
    {
        get { return m_Category; }
        set { m_Category = value; }
    }

    private string m_CategoryId;
    public string CategoryId
    {
        get { return m_CategoryId; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.BindCategory();
        }
    }

    private void BindCategory()
    {
        try
        {
            Category aCategory =
            this.m_CategoryManager.GetCategoryByName(this.m_Category);
            this.rptCategory.DataSource = this.m_CategoryManager.GetSubCateogoriesBySupCategory(aCategory).OrderBy(theCategory => theCategory.Index).Take(this.m_ShowCount);
            this.rptCategory.DataBind();
            this.m_CategoryId = aCategory.CategoryId.ToString();
            HtmlImage image = null;
            foreach (var theControl in rptCategory.Controls)
            {
                if ((theControl is RepeaterItem) && ((theControl as RepeaterItem).ItemType == ListItemType.Header))
                {
                    image = (theControl as RepeaterItem).FindControl("imgHead") as HtmlImage;
                }
                image.Src = imageSrc;
            }
           
        }
        catch
        { }
    }
}